﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Marketplace;
using System.Xml.Linq;
using MichMan.Utilities;

namespace Subsonic.Pages
{
    public partial class HelpPage : PhoneApplicationPage
    {
        public HelpPage()
        {
            InitializeComponent();
            webBrowser.Loaded += new RoutedEventHandler(webBrowser_Loaded);
        }

        void webBrowser_Loaded(object sender, RoutedEventArgs e)
        {
            Stream stream = Application.GetResourceStream(new Uri("Resources/Help.html", UriKind.Relative)).Stream;

            XElement xeltHtml = XElement.Load(stream);

            LicenseInformation lisc = new LicenseInformation();
            if (lisc.IsTrial())
            {
                XElement ownerBlock = xeltHtml.GetElementById("OwnerBlock");
                ownerBlock.Remove();
            }
            else
            {
                XElement trialBlock = xeltHtml.GetElementById("TrialBlock");
                trialBlock.Remove();
            }

            webBrowser.NavigateToString(xeltHtml.ToString());
        }

        private void webBrowser_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (e.Value == "upgrade")
            {
                MarketplaceDetailTask detailTask = new MarketplaceDetailTask();
                detailTask.Show();
            }
        }
    }
}